package com.superzqb.asus.superzqbFragment.superzqbSave;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.baoyz.widget.PullRefreshLayout;
import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbSave.Adapter.MyAimAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MyAim extends Activity implements View.OnClickListener{
    private PullRefreshLayout layout;
    private ListView aimList;
    private ImageView back;
    private TextView title;
    private Context context;
    private MyAimAdapter adapter;
    public static ArrayList<Map<String, Object>> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_aim);
        initView();
        getLv();
        adapter=new MyAimAdapter(context,list);
        aimList.setAdapter(adapter);
        layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                layout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        layout.setRefreshing(false);
                        getLv();
                    }
                }, 2000);
            }
        });
    }

    private void initView() {
        context=MyAim.this;
        back=(ImageView)findViewById(R.id.back);
        title=(TextView) findViewById(R.id.title);
        title.setText("我的目标");
        aimList=(ListView)findViewById(R.id.aimList);
        layout= (PullRefreshLayout)findViewById(R.id.swipeRefreshLayout);

        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            default:break;
        }
    }

    public void getLv() {
        list.clear();
        for(int i=0;i<3;i++) {
            Map<String, Object> map = new HashMap<>();
            //键一般为"字符串"
            if(0==i){
                map.put("addGoods", "iphone7");
                map.put("money", "4512");
                map.put("progress", "10");
                map.put("saved","451.2");
                map.put("toSave", "14");
            } else if (1 == i) {
                map.put("addGoods", "分期小助手-男鞋新百伦");
                map.put("money", "600");
                map.put("progress", "5");
                map.put("saved","247");
                map.put("toSave", "14");
            }else if (2 == i) {
                map.put("addGoods", "暑假旅行经费");
                map.put("money", "3000");
                map.put("progress", "0");
                map.put("saved","0");
                map.put("toSave", "45");
            }
            list.add(map);
        }

    }
}
